package ink.yql.controller;

import ink.yql.model.TeamUser;
import ink.yql.service.TeamUserService;
import ink.yql.util.RestObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author YQL
 */
@RestController
@RequestMapping("/team_user")
public class TeamUserController {
    @Autowired
    private TeamUserService teamUserService;

    @GetMapping("/{tid}/{sendTime}")
    public RestObject getByTid( @PathVariable("tid") Integer tid, @PathVariable("sendTime") Long sendTime) {
        // 保护措施  以防拿到url一直请求
        if (System.currentTimeMillis() / 1000 - sendTime > 3) {
            return RestObject.builder().code("400").message("请求时间超时").build();
        }
        return  teamUserService.getByTid(tid);
    }
    @GetMapping("/{sendTime}")
    public RestObject getByTid(@PathVariable("sendTime") Long sendTime) {
        // 保护措施  以防拿到url一直请求
        if (System.currentTimeMillis() / 1000 - sendTime > 3) {
            return RestObject.builder().code("400").message("请求时间超时").build();
        }
        return  teamUserService.getByUid();
    }
    @PostMapping("/{sendTime}")
    public RestObject addOne(@RequestBody TeamUser teamUser, @PathVariable("sendTime") Long sendTime) {
        // 保护措施  以防拿到url一直请求
        if (System.currentTimeMillis() / 1000 - sendTime > 3) {
            return RestObject.builder().code("400").message("请求时间超时").build();
        }
        return  teamUserService.addOne(teamUser);
    }
    @DeleteMapping("/{sendTime}")
    public RestObject delete(@RequestBody TeamUser teamUser, @PathVariable("sendTime") Long sendTime) {
        // 保护措施  以防拿到url一直请求
        if (System.currentTimeMillis() / 1000 - sendTime > 3) {
            return RestObject.builder().code("400").message("请求时间超时").build();
        }
        return  teamUserService.delete(teamUser);
    }

}
